import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sabre_sync_fencing/dd_core/dd_other.dart';

import '../../../dd_core/dd_config.dart';
import '../../../dd_core/dd_log_service.dart';
import '../../../r.dart';
import '../controllers/dd_login_controller.dart';

class DDLoginPage extends StatefulWidget {
  const DDLoginPage({Key? key}) : super(key: key);

  @override
  State<DDLoginPage> createState() => _DDLoginPageState();
}

class _DDLoginPageState extends State<DDLoginPage> {
  DDLoginController _controller = DDLoginController();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DDLoginController>(
        init: _controller,
        initState: (state) {},
        dispose: (state) {},
        builder: (controller) {
          return Scaffold(
              backgroundColor: Color(0xFFE7F6FC),
              body: SafeArea(
                  top: true,
                  child: SingleChildScrollView(
                    child: Obx(
                      () => Column(
                        mainAxisSize: MainAxisSize.max,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: [
                          Align(
                            alignment: AlignmentDirectional(0, 0),
                            child: Padding(
                              padding:
                                  EdgeInsetsDirectional.fromSTEB(0, 38, 0, 0),
                              child: Text(
                                'welcome',
                                style: TextStyle(
                                  fontFamily: 'ModakRegular',
                                  color: Color(0xFF53BFD7),
                                  fontSize: 44,
                                  //fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsetsDirectional.fromSTEB(
                                0, 12 * DDScreenUtil.getHeightRatio(), 0, 0),
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(8),
                              child: Image.asset(
                                R.assetsImagesSlice520,
                                fit: BoxFit.fill,
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsetsDirectional.fromSTEB(
                                28, 50 * DDScreenUtil.getHeightRatio(), 28, 0),
                            child: Stack(
                              children: [
                                Positioned.fill(
                                  child: Image.asset(
                                    R.assetsImagesLoginBtn2,
                                    fit: BoxFit.fill,
                                    // fit: BoxFit.cover,
                                  ),
                                ),
                                DDLoginSafeButton(
                                  onPressed: () {
                                    DDLogService().ddGa(page: "applelogin");
                                    if (!_controller.isToggled.value) {
                                      _controller.selectLoginType = "apple";
                                      _controller.showPrivacyDialog(context);
                                    } else {
                                      _controller.appleSign();
                                    }
                                  },
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Image.asset(R.assetsImagesAppleLogo),
                                      SizedBox(width: 8),
                                      Text(
                                        'Sign in with Apple',
                                        style: TextStyle(
                                          fontFamily: 'LINESeedSans_A_XBd',
                                          color: Color(0xFF0A1117),
                                          fontSize: 16,
                                          //letterSpacing: 0,
                                          fontWeight: FontWeight.bold,
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Padding(
                            padding: EdgeInsetsDirectional.fromSTEB(
                                28, 26 * DDScreenUtil.getHeightRatio(), 28, 0),
                            child:
                            Container(
                            //  width: Get.width - 56,
                              child: Stack(
                                children: [
                                  Positioned.fill(
                                    child: Image.asset(
                                      R.assetsImagesLoginBtn1,
                                      fit: BoxFit.fill,
                                     // fit: BoxFit.cover,
                                    ),
                                  ),
                                  DDLoginSafeButton(
                                    onPressed: () {
                                      DDLogService().ddGa(page: "quicklogin");
                                      if (!_controller.isToggled.value) {
                                        _controller.selectLoginType = "fast";
                                        _controller.showPrivacyDialog(context);
                                      } else {
                                        _controller.fastLogin();
                                      }
                                    },
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Image.asset(R.assetsImagesFastLogin),
                                        SizedBox(width: 8),
                                        Text(
                                          'Fast Login             ',
                                          style: TextStyle(
                                            fontFamily: 'LINESeedSans_A_XBd',
                                            color: Color(0xFFFFFFFF),
                                            fontSize: 16,
                                            letterSpacing: 0,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsetsDirectional.fromSTEB(
                              59,
                              38 * DDScreenUtil.getHeightRatio(),
                              59,
                              38 * DDScreenUtil.getHeightRatio(),
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                GestureDetector(
                                  onTap: () {
                                    _controller.isToggled.value =
                                        !_controller.isToggled.value;
                                  },
                                  child: _controller.isToggled.value == true
                                      ? Image.asset(
                                          R.assetsImagesLoginSelect,
                                          width: 16,
                                          height: 16,
                                        )
                                      : Image.asset(
                                          R.assetsImagesLoginSelectNor,
                                          width: 16,
                                          height: 16,
                                        ),
                                ),
                                SizedBox(
                                  width: 4,
                                ),
                                Expanded(
                                  child: RichText(
                                    text: TextSpan(
                                      text:
                                          'By using our App you agree with our ',
                                      style: TextStyle(
                                        fontFamily: 'Readex Pro',
                                        color: Color(0xFF0C1011),
                                        fontSize: 12,
                                        letterSpacing: 0,
                                      ),
                                      children: [
                                        TextSpan(
                                          text: 'Term of Use',
                                          style: TextStyle(
                                            color: Colors.blue,
                                            decoration:
                                                TextDecoration.underline,
                                          ),
                                          recognizer: TapGestureRecognizer()
                                            ..onTap =
                                                _controller.onTermOfUseTap,
                                        ),
                                        TextSpan(
                                          text: ' and ',
                                          style: TextStyle(
                                            fontFamily: 'Readex Pro',
                                            color: Color(0xFF0C1011),
                                            fontSize: 12,
                                            letterSpacing: 0,
                                          ),
                                        ),
                                        TextSpan(
                                          text: 'Privacy Policy.',
                                          style: TextStyle(
                                            color: Colors.blue,
                                            decoration:
                                                TextDecoration.underline,
                                          ),
                                          recognizer: TapGestureRecognizer()
                                            ..onTap =
                                                _controller.onPrivacyPolicyTap,
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  )));
        });
  }
}
